﻿@page
@using Microsoft.AspNetCore.Http.Features
@model TwoFactorAuthenticationModel
@{
    ViewData["Title"] = "双因素身份验证 (2FA)";
    ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
}

<partial name="_StatusMessage" for="StatusMessage" />
<h3>@ViewData["Title"]</h3>
@{
    var consentFeature = HttpContext.Features.Get<ITrackingConsentFeature>();
    @if (consentFeature?.CanTrack ?? true)
    {
        @if (Model.Is2faEnabled)
        {
            if (Model.RecoveryCodesLeft == 0)
            {
                <div class="alert alert-danger">
                    <strong>您没有剩余的恢复代码.</strong>
                    <p>你必须 <a asp-page="./GenerateRecoveryCodes">生成一组新的恢复代码</a> 在您可以使用恢复代码登录之前.</p>
                </div>
            }
            else if (Model.RecoveryCodesLeft == 1)
            {
                <div class="alert alert-danger">
                    <strong>您还剩 1 个恢复代码.</strong>
                    <p>你可以 <a asp-page="./GenerateRecoveryCodes">生成一组新的恢复代码</a>.</p>
                </div>
            }
            else if (Model.RecoveryCodesLeft <= 3)
            {
                <div class="alert alert-warning">
                    <strong>你有 @Model.RecoveryCodesLeft 剩余恢复代码.</strong>
                    <p>你应该 <a asp-page="./GenerateRecoveryCodes">生成一组新的恢复代码</a>.</p>
                </div>
            }

            if (Model.IsMachineRemembered)
            {
                <form method="post" style="display: inline-block">
                    <button type="submit" class="btn btn-primary">忘记这个浏览器</button>
                </form>
            }
            <a asp-page="./Disable2fa" class="btn btn-primary">禁用 2FA</a>
            <a asp-page="./GenerateRecoveryCodes" class="btn btn-primary">重置恢复代码</a>
        }

        <h4>身份验证器应用程序</h4>
        @if (!Model.HasAuthenticator)
        {
            <a id="enable-authenticator" asp-page="./EnableAuthenticator" class="btn btn-primary">添加验证器应用</a>
        }
        else
        {
            <a id="enable-authenticator" asp-page="./EnableAuthenticator" class="btn btn-primary">设置身份验证器应用程序</a>
            <a id="reset-authenticator" asp-page="./ResetAuthenticator" class="btn btn-primary">重置验证器应用程序</a>
        }
    }
    else
    {
        <div class="alert alert-danger">
            <strong>隐私和 cookie 政策未被接受.</strong>
            <p>您必须先接受该策略，然后才能启用双因素身份验证.</p>
        </div>
    }
}

@section Scripts {
    <partial name="_ValidationScriptsPartial" />
}
